package player

import (
	"GameServer/Common/utils"
	"GameServer/Game/errors"
	"GameServer/Game/lib"
	"GameServer/Game/sp"
)

// 8700 收集道具信息
func (p *Player) ColloctPropInfoRequest(req *sp.ColloctPropInfoRequest) (res *sp.ColloctPropInfoResponse) {
	us := p.User
	uColloctProp, err := lib.GetColloctProp(us)
	if err != nil {
		res = &sp.ColloctPropInfoResponse{
			Errcode: errors.ErrCode(err),
		}
		return
	}

	res = &sp.ColloctPropInfoResponse{
		Prop: lib.FormatColloctProp(uColloctProp),
	}
	return
}

// 8701 收集道具 状态完成，通知客户端 s-c
// func (p *Player) colloctPropNotice() {
// 	req := &sp.ColloctPropNoticeRequest{}
// 	p.Send(req)
// 	return
// }

// 8702 收集道具 领取奖励
func (p *Player) ColloctPropRewardRequest(req *sp.ColloctPropRewardRequest) (res *sp.ColloctPropRewardResponse) {
	us := p.User

	uColloctProp, uProp, resGoods, boxRes, err := lib.GetColloctPropReward("ColloctPropRewardRequest", us, req.ActivId, req.Level, p.Send)
	if err != nil {
		res = &sp.ColloctPropRewardResponse{
			Errcode: errors.ErrCode(err),
		}
		return
	}

	res = &sp.ColloctPropRewardResponse{
		Prop:   lib.FormatColloctProp(uColloctProp),
		Res:    lib.FormatGoodsInfoSps(resGoods),
		BoxRes: lib.FormatBoxResSps(boxRes),
	}

	p.TimelyUpdateProp(req.GetType(), uProp)
	utils.AsyncFunc(func() {
		p.UpdateProp(req.GetType(), uProp)
	})
	return
}
